﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace BigVisibleCountdown
{
    public class TimeDisplayConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var clock = value as CountdownTimer;

            if (clock.Hours > 0)
            {
                return string.Format("{0}:{1:D2}:{2:D2}", clock.Hours, clock.Minutes, clock.Seconds);
            }

            if (clock.Minutes > 0)
            {
                return string.Format("{0}:{1:D2}", clock.Minutes, clock.Seconds);
            }

            if (clock.Seconds > 0)
            {
                return string.Format("{0}", clock.Seconds);
            }

            if (clock.Seconds <= 0)
            {
                return "Times Up";
            }

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new System.NotImplementedException();
        }
    }
}
